#! /bin/sh

cd "`dirname \"$0\"`"/.. &&
umask 022 &&
chmod -R a+rX . &&

set-commit-date.py &&
devscripts/build-docs &&

python setup.py build_py &&
python setup.py build --executable '/usr/bin/env python' &&
python setup.py sdist &&

find build -name '*.py[co]' -delete &&
python setup.py bdist_wheel --universal &&

version=`python setup.py --version`
. `dirname $0`/split_tag.sh &&
split_tag $version

if [ "$state" = final ]; then
   rsync -ahP4 dist/* frs.sourceforge.net:/home/frs/project/sqlobject/sqlobject/"$version"/ &&
   rsync -ahP4 ANNOUNCE.rst frs.sourceforge.net:/home/frs/project/sqlobject/sqlobject/"$version"/README.rst || exit 1
   devscripts/sftp-frs
fi &&

twine upload --skip-existing dist/* &&
exec rm -rf build dist docs/html SQLObject.egg-info
